package com.mine.redis.util.service;

import com.mine.redis.util.bean.ShopDO;
import com.mine.redis.util.mapper.ShopMapper;
import com.mine.redis.util.utils.cache.CacheClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

import static com.mine.redis.util.utils.cache.CacheConstants.SHOP_CACHE_KEY;
import static com.mine.redis.util.utils.cache.CacheConstants.SHOP_CACHE_TTL;

/**
 * @author weixiao
 * @date 2024/8/15 15:01
 */
@Service
public class ShopService {

    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private CacheClient cacheClient;

    public ShopDO getShopById(int id) {
        //return cacheClient.getWithCacheThrough(SHOP_CACHE_KEY + id, ShopDO.class, id, shopMapper::getById, SHOP_CACHE_TTL, TimeUnit.SECONDS);
        //return cacheClient.getWithLock(SHOP_CACHE_KEY + id, ShopDO.class, id, shopMapper::getById, SHOP_CACHE_TTL, TimeUnit.SECONDS);
        return cacheClient.getWithLogicExpire(SHOP_CACHE_KEY + id, ShopDO.class, id, shopMapper::getById, SHOP_CACHE_TTL, TimeUnit.SECONDS);
    }
}
